/* openfire.h generated Mon Dec 14 20:21:10 2009 GMT+2 */
#ifndef _OPENFIRE_H_
#define _OPENFIRE_H_

#ifndef DLLIMPORT
  #ifdef _WIN32
    #define DLLIMPORT(x) extern __stdcall x
  #else
    #define DLLIMPORT(x) x
  #endif
#endif

#include "shared.h"
#include "networking.h"

/*** Source: dev/xfire/XfirePacketAnalyze.h ***/
#define XFPREF_ENABLE_SOUNDS 0x04
#define XFPREF_ENABLE_ENGROSSED_SOUNDS 0x05
#define XFPREF_ENABLE_TIMESTAMPS 0x06
#define XFPREF_ENABLE_JOIN_LEAVE_SOUNDS 0x07
#define XFPREF_ENABLE_JOIN_LEAVE_GROUPCHAT_SOUNDS 0x08
#define XFPREF_ENABLE_VOICECHAT_CALL_SOUNDS 0x09
#define XFPREF_TOOLTIP_LOGON 0x10
#define XFPREF_TOOLTIP_DOWNLOADS 0x11
#define XFPREF_ENABLE_SCREENSHOT_SOUNDS 0x12
#define XFPREF_SHOW_FOF 0x13
#define XFPREF_SHOW_OFFLINE_FRIENDS 0x14
#define XFVALUE_GC_JOIN_SUCCESS 0x00
#define XFVALUE_GC_JOIN_NEED_PASSWORD 0x04
#define XFVALUE_GC_JOIN_WRONG_PASSWORD 0x05
#define XFVALUE_GC_TYPE_NORMAL 0x01
#define XFVALUE_GC_TYPE_LIVE 0x03
#define XFP_IS_PREF(prefset, offset) (  (prefset)&( 1 << (offset) )  )
#define XFP_SET_PREF(prefset, offset) prefset |= ( 1 << (offset) )
#define XFP_DEL_PREF(prefset, offset) prefset &= ~( 1 << (offset) )
#define XFNH_CONTINUE 0
#define XFNH_NOHANDLE 0x1
#define XFNH_NOITERATION 0x2
#define XFNH_FATAL 0x4
#define XFNH_USER_MASK 0xffff0000
#define XFIH_FATAL -5				/* fatal error, try to quit as fast as possible */
#define XFIH_PARSING_FAILED -4		/* parsing network packet failed */
#define XFIH_OTHER_ERROR -3			/* reserved for future use */
#define XFIH_NULL_INST -2			/* NULL XFINST was passed */
#define XFIH_SOCKET_ERROR -1		/* socket reported error, OS specific error functions might have more data */
#define XFIH_SOCKET_CLOSED 0		/* connection was closed on the socket */
#define XFIH_PENDING 0x1	/* data or handlers pending */
#define XFIH_HANDLED 0x2	/* packet was handled */
#define XFIH_UNKNOWN 0x4	/* packet was unknown */
#define XFIH_EXTERNAL 0x8	/* external handlers were called */
#define XFIH_NONFATAL 0x10	/* a non-fatal error was encountered */
#define XFIH_BLOCKED 0x20	/* external handler wanted to prevent internal handler where impossible */
#define XFIH_MORE 0x40		/* external handler wanted to prevent internal handler where impossible */
#define XFSEL_OK 1
#define XFSEL_READ 2
#define XFSEL_WRITE 4
struct XfVersionUpdate {
	unsigned int version;
	non0string  *fileurl;
	unsigned int command;
	unsigned int fileid;
};
struct XfFriendInvite {
	non0string   *username;
	non0string   *nickname;
	non0string   *invite_text;
};
struct XfFriendSearchResult {
	non0string   *name;
	non0string   *lname;
	non0string   *fname;
};
struct XfClanInvite {
	unsigned int  clanid;
	non0string   *shortname;
	non0string   *longname;
	unsigned int  clantype;
	non0string   *username;
	non0string   *nickname;
	non0string   *invite_text;
};
struct XfFriendsGroup {
	unsigned int  groupid;
	non0string   *name;
	LinkedList   *users; /* Pointers to XfFriend structures */
};
struct XfGameServerList {
	unsigned int gameid;
	LinkedList  *servers; /* struct XfGameData */
};
struct XfGameDataExt {
	LinkedList *names;
	LinkedList *values;
	/* The rest only used for friends' favorites */
	LinkedList *byfriends; /* Pointers to XfFriend structures */
};
struct XfGameData {
	unsigned int          gameid;
	unsigned int          ip;
	unsigned int          port;
	unsigned int          gameid_old;
	unsigned int          ip_old;
	unsigned int          port_old;
	struct XfGameDataExt *extdata;
};
struct XfFavoriteServers {
	unsigned int  maxfavorites;
	LinkedList   *servers;
};
struct XfScreenshotInfo {
	unsigned int       index;
	struct XfGameData *game;
	non0string        *description;
	unsigned int       timestamp;
	non0string        *guid;
	unsigned int       locked;
	unsigned int       filesize;
};
struct XfVideoInfo {
	unsigned int       index;
	non0string        *title;
	non0string        *description;
	unsigned int       filesize;
	unsigned int       res_x;
	unsigned int       res_y;
	unsigned int       frames;
	unsigned int       fps;
	unsigned int       gameid;
	unsigned int       timestamp;
};
struct XfClanMember {
	struct XfFriend *user; /* The actual user structure */
	struct XfClan *clan;   /* Link to the clan */
	non0string *nickname;  /* Nickname in this clan */
};
struct XfClanNews {
	unsigned int newsid;
	struct XfClan *clan;   /* Link to the clan */
	non0string  *title;
	unsigned int timestamp;
	non0string  *username;
	non0string  *nickname;
	non0string  *extra;
};
struct XfClanEvent {
	unsigned int eventid;
	struct XfClan *clan;   /* Link to the clan */
	unsigned int gameid;
	non0string  *title;
	unsigned int starttime;
	unsigned int endtime;
};
struct XfClan {
	unsigned int clanid;
	non0string  *shortname; /* Clan shortname (url name) */
	non0string  *longname;  /* Clan long name */
	BTree       *members;   /* BTree of XfClanMember structs */
	LinkedList  *news;		/* LinkedList of XfClanNews structs */
	LinkedList  *events;	/* LinkedList of XfClanEvent structs */
	unsigned int clantype;
};
struct XfFriendP2P {
	unsigned int ip;
	unsigned int port;
	unsigned int localip;
	unsigned int localport;
	unsigned int status;
	non0string  *salt;
};
struct XfBroadcast {
	non0string  *title;
	non0string  *description;
	non0string  *sessionid;
	non0string  *sessionimage;
	non0string  *ipaddress;
	non0string  *watchers;
	non0string  *ipport;
	unsigned int friends_only;
};
struct XfFriendExt {
	LinkedList         *screenshots;
	LinkedList         *videos;
	LinkedList         *clans;
	unsigned int        avatartype;
	unsigned int        avatarnumber;
	struct XfFriendP2P *p2p;
	struct XfBroadcast *live_video;
};
struct XfFriend {
	unsigned int        userid;
	non0string         *sid;
	non0string         *username;
	non0string         *nickname;
	non0string         *status;
	struct XfGameData  *game;
	struct XfGameData  *voice;
	struct XfFriendExt *extdata;
	void               *freedata; /* for host program to use */
};
struct XfChatRoomUser {
	struct XfFriend *user;
	unsigned int     permission;
	unsigned int     using_voice;
	void            *freedata; /* for host program to use */
};
struct XfVoiceHostUser {
	unsigned int ip;
	unsigned int port;
	unsigned int localip;
	unsigned int localport;
	unsigned int status;
	non0string  *salt;
};
struct XfChatRoomVoice {
	non0string   *session_id;
	struct XfVoiceHostUser  *host_info;
	unsigned int  host_type;
	unsigned int  voice_enabled;
	unsigned int  host_userid;
	unsigned int  max_participants;
	unsigned int  voice_quality;
	unsigned int  voice_ip;
	unsigned int  voice_port;
};
struct XfChatRoom {
	non0string  *gcid;
	non0string  *name;
	non0string  *motd;
	BTree       *users;
	unsigned int info_timestamp;
	unsigned int info_usercount;
	unsigned int set_saved;
	unsigned int set_silenced;
	unsigned int set_showjoinpart;
	unsigned int set_defaultperm;
	unsigned int set_protected;
	unsigned int set_access;
	unsigned int set_allowvoice;
	unsigned int set_type;
	struct XfChatRoomVoice *voice;
	struct XfChatRoomUser *self;
	void        *freedata;
};
struct XfNetworkHandlerList {
	unsigned int pid;
	LinkedList  *funcs;
};
struct XfNetworkInstance {
	int          sock;             /* Connection socket */
	BTree       *network_handlers; /* Registered network packet handlers */
	non0string  *incoming;         /* Incoming buffer */
	size_t       in_completed;     /* Completed bytes in incoming buffer */
	non0string  *outgoing;         /* Outgoing buffer */
	size_t       out_completed;    /* Completed bytes in outgoing buffer */
	LinkedList  *send_queue;       /* Packet queue */
	fd_set      *readset;          /* File descriptors for reading */
	fd_set      *writeset;         /* File descriptros for writing */
	fd_set      *xfireset;         /* All file descriptors used by Openfire-C */
	int          fdmax;            /* The largest file descriptor in readset/writeset/xfireset */
	void        *unused;
};
typedef struct StructXfireInstance {
	struct XfNetworkInstance *network;
	struct XfFriend          *self;         /* Includes userid, sid, nick, status, clans, screenshots of self */
	BTree                    *friends;      /* BTree of XfFriend structs (friends) */
	BTree                    *other_people; /* BTree of XfFriend structs (other known people such as clanmates and fof) */
	BTree                    *groups;       /* BTree of XfFriendsGroup structs */
	struct XfFavoriteServers *fav_servers;  /* Favorite servers */
	BTree                    *chatrooms;    /* BTree of XfChatRoom structs */
	unsigned int              prefs;        /* Xfire client preferences */
	BTree                    *known_clans;  /* BTree of all clans of you and your friends for lookup */
	BTree                    *online_people;/* BTree of all online people for faster lookup */
	BTree                    *friends_favs; /* BTree of XfGameServerList structs */
	BTree                    *game_servers; /* BTree of XfGameServerList structs */
	unsigned int              imindex;      /* auto-incremented index for sent messages */
	unsigned int              debug;        /* Set library debug message level, 0 = no messages */
	/* TODO: File transfer stuff like channels */
	void *placeholder3;
	/* Replace above with some meaningful structs... now they are just to fill the struct to multiple of 4 */
	void                     *freedata;     /* Reserved for host program */
} *XFINST;
struct XfNetworkHandler {
	void *func;
	void *freedata;
};

/*** Source: dev/xfire/XfirePacketID.h ***/
#define XFPID_RAW 0xffff
#define XFPIDP_IM_IM 0x0000
#define XFPIDP_IM_ACK 0x0001
#define XFPIDP_IM_P2P 0x0002
#define XFPIDP_IM_TYPING 0x0003
#define XFPIDP_DLPEER_INFO 0x3a9c
#define XFPIDP_DLPEER_FILES 0x3a9d
#define XFPIDP_DLPEER_STATUS 0x3a9e
#define XFPIDP_GC_JOIN 0x4cf4
#define XFPIDP_GC_LEAVE 0x4cf5
#define XFPIDP_GC_MESSAGE 0x4cf6
#define XFPIDP_GC_CNAME 0x4cf8
#define XFPIDP_GC_CLVL 0x4cf9
#define XFPIDP_GC_REQINFO 0x4cfa
#define XFPIDP_GC_KICK 0x4cfb
#define XFPIDP_GC_INVITE 0x4cfc
#define XFPIDP_GC_CPERSISTENT 0x4cfd /* should this be renamed? */
#define XFPIDP_GC_CVOICE 0x4cfe
#define XFPIDP_GC_INVITEDENY 0x4cff
#define XFPIDP_GC_VOICEJOIN 0x4d01
#define XFPIDP_GC_VOICELEAVE 0x4d02
#define XFPIDP_GC_VOICEOFF 0x4d04 /* obsolete */
#define XFPIDP_GC_VOICEHOST 0x4d05
#define XFPIDP_GC_QUERY 0x4d06
#define XFPIDP_GC_CDEFLVL 0x4d08
#define XFPIDP_GC_CMOTD 0x4d0c
#define XFPIDP_GC_CVOICEALLOW 0x4d0d /* obsolete */
#define XFPIDP_GC_VOICEJOINSESSION 0x4d11
#define XFPIDP_GC_QNAME 0x4d14
#define XFPIDP_GC_SETPASSWORD 0x4d15
#define XFPIDP_GC_CACCESS 0x4d16
#define XFPIDP_GC_CSILENCE 0x4d17
#define XFPIDP_GC_CJOINPARTMSG 0x4d18
#define XFPIDC_LOGIN 0x0001
#define XFPIDC_CLIENTVERSION 0x0003
#define XFPIDC_CLIENTINFO 0x0010
#define XFPIDC_PEERINFO 0x0011
#define XFPIDC_PREFS 0x000a
#define XFPIDC_HEARTBEAT 0x000d
#define XFPIDC_GAMESTATUS 0x0004
#define XFPIDC_FNETWORK 0x0005
#define XFPIDC_FRIENDINVITE 0x0006
#define XFPIDC_ACCEPTINVITE 0x0007
#define XFPIDC_REJECTINVITE 0x0008
#define XFPIDC_DELETEFRIEND 0x0009
#define XFPIDC_FRIENDSEARCH 0x000c
#define XFPIDC_CHANGENICK 0x000e
#define XFPIDC_VOICESTATUS 0x000f /* confirm this */
#define XFPIDC_GROUPCREATE 0x001a
#define XFPIDC_GROUPDELETE 0x001b
#define XFPIDC_GROUPRENAME 0x001c
#define XFPIDC_ADDTOGROUP 0x001d
#define XFPIDC_REMOVEFROMGROUP 0x001e
#define XFPIDC_TEXTSTATUS 0x0020
#define XFPIDC_GAMEINFO 0x0023
#define XFPIDC_ADVINFOREQUEST 0x0025
#define XFPIDC_IM 0x0002
#define XFPIDC_IM_IM (XFPIDP_IM_IM << 16) | XFPIDC_IM
#define XFPIDC_IM_ACK (XFPIDP_IM_ACK << 16) | XFPIDC_IM
#define XFPIDC_IM_P2P (XFPIDP_IM_P2P << 16) | XFPIDC_IM
#define XFPIDC_IM_TYPING (XFPIDP_IM_TYPING << 16) | XFPIDC_IM
#define XFPIDC_DLPEER 0x0017
#define XFPIDC_DLPEER_INFO (XFPIDP_DLPEER_INFO << 16) | XFPIDC_DLPEER
#define XFPIDC_DLPEER_FILES (XFPIDP_DLPEER_FILES << 16) | XFPIDC_DLPEER
#define XFPIDC_DLPEER_STATUS (XFPIDP_DLPEER_STATUS << 16) | XFPIDC_DLPEER
#define XFPIDC_DLFILES 0x0018
#define XFPIDC_GC 0x0019
#define XFPIDC_GC_JOIN (XFPIDP_GC_JOIN << 16) | XFPIDC_GC
#define XFPIDC_GC_LEAVE (XFPIDP_GC_LEAVE << 16) | XFPIDC_GC
#define XFPIDC_GC_MESSAGE (XFPIDP_GC_MESSAGE << 16) | XFPIDC_GC
#define XFPIDC_GC_CNAME (XFPIDP_GC_CNAME << 16) | XFPIDC_GC
#define XFPIDC_GC_CLVL (XFPIDP_GC_CLVL << 16) | XFPIDC_GC
#define XFPIDC_GC_REQINFO (XFPIDP_GC_REQINFO << 16) | XFPIDC_GC
#define XFPIDC_GC_KICK (XFPIDP_GC_KICK << 16) | XFPIDC_GC
#define XFPIDC_GC_INVITE (XFPIDP_GC_INVITE << 16) | XFPIDC_GC
#define XFPIDC_GC_CPERSISTENT (XFPIDP_GC_CPERSISTENT << 16) | XFPIDC_GC /* rename? */
#define XFPIDC_GC_CVOICE (XFPIDP_GC_CVOICE << 16) | XFPIDC_GC
#define XFPIDC_GC_INVITEDENY (XFPIDP_GC_INVITEDENY << 16) | XFPIDC_GC
#define XFPIDC_GC_VOICEJOIN (XFPIDP_GC_VOICEJOIN << 16) | XFPIDC_GC
#define XFPIDC_GC_VOICELEAVE (XFPIDP_GC_VOICELEAVE << 16) | XFPIDC_GC
#define XFPIDC_GC_VOICEOFF (XFPIDP_GC_VOICEOFF << 16) | XFPIDC_GC /* obsolete */
#define XFPIDC_GC_VOICEHOST (XFPIDP_GC_VOICEHOST << 16) | XFPIDC_GC
#define XFPIDC_GC_QUERY (XFPIDP_GC_QUERY << 16) | XFPIDC_GC
#define XFPIDC_GC_CDEFLVL (XFPIDP_GC_CDEFLVL << 16) | XFPIDC_GC
#define XFPIDC_GC_CMOTD (XFPIDP_GC_CMOTD << 16) | XFPIDC_GC
#define XFPIDC_GC_CVOICEALLOW (XFPIDP_GC_CVOICEALLOW << 16) | XFPIDC_GC /* obsolete */
#define XFPIDC_GC_VOICEJOINSESSION (XFPIDP_GC_VOICEJOINSESSION << 16) | XFPIDC_GC
#define XFPIDC_GC_QNAME (XFPIDP_GC_QNAME << 16) | XFPIDC_GC
#define XFPIDC_GC_SETPASSWORD (XFPIDP_GC_SETPASSWORD << 16) | XFPIDC_GC
#define XFPIDC_GC_CACCESS (XFPIDP_GC_CACCESS << 16) | XFPIDC_GC
#define XFPIDC_GC_CSILENCE (XFPIDP_GC_CSILENCE << 16) | XFPIDC_GC
#define XFPIDC_GC_CJOINPARTMSG (XFPIDP_GC_CJOINPARTMSG << 16) | XFPIDC_GC
#define XFPIDC_ADDFAV 0x0013
#define XFPIDC_DELFAV 0x0014
#define XFPIDC_FRIENDFAV 0x0015
#define XFPIDC_SERVERS 0x0016
#define XFPIDC_LIVELIDEO 0x0026
#define XFPIDS_LOGINSALT 0x0080
#define XFPIDS_INVALIDLOGIN 0x0081
#define XFPIDS_CLIENTINFO 0x0082
#define XFPIDS_WRONGVERSION 0x0086
#define XFPIDS_PREFS 0x008d
#define XFPIDS_GROUPS 0x0097
#define XFPIDS_INGROUPS 0x0098
#define XFPIDS_MYSCREENSHOTS 0x009d
#define XFPIDS_CONNECTIP 0x00af
#define XFPIDS_HEARTBEAT 0x0090
#define XFPIDS_FRIENDS 0x0083
#define XFPIDS_ONLINESTATUS 0x0084
#define XFPIDS_GAMESTATUS 0x0087
#define XFPIDS_FNETWORK 0x0088
#define XFPIDS_INVITESTATUS 0x0089
#define XFPIDS_FRIENDINVITE 0x008a
#define XFPIDS_DELETEFRIEND 0x008b
#define XFPIDS_FRIENDSEARCH 0x008f
#define XFPIDS_VOICESTATUS 0x0093
#define XFPIDS_GROUPCREATE 0x0099
#define XFPIDS_TEXTSTATUS 0x009a
#define XFPIDS_GAMEINFO 0x009c
#define XFPIDS_CHANGENICK 0x00a1
#define XFPIDS_SCREENSHOTS 0x00ac
#define XFPIDS_ADVINFOUPDATE 0x00ad
#define XFPIDS_AVATAR 0x00ae
#define XFPIDS_CLANS 0x00b0
#define XFPIDS_VIDEOS 0x00b6
#define XFPIDS_EGAME 0x00b7
#define XFPIDS_IM 0x0085
#define XFPIDS_IM_IM (XFPIDP_IM_IM << 16) | XFPIDS_IM
#define XFPIDS_IM_ACK (XFPIDP_IM_ACK << 16) | XFPIDS_IM
#define XFPIDS_IM_P2P (XFPIDP_IM_P2P << 16) | XFPIDS_IM
#define XFPIDS_IM_TYPING (XFPIDP_IM_TYPING << 16) | XFPIDS_IM
#define XFPIDS_BROADCAST 0x00a9
#define XFPIDS_PEERINFO 0x0190
#define XFPIDS_PEERINFO_OTHER 0x0191
#define XFPIDS_NEWCHANNEL 0x01c2
#define XFPIDS_MYCLANS 0x009e
#define XFPIDS_CLANMEMBERS 0x009f
#define XFPIDS_LEFTCLAN 0x00a0
#define XFPIDS_CLANNICK 0x00a2
#define XFPIDS_CLANORDER 0x00a3 /* NO! All groups in friends list, including Friends Online (and Offline, FoF?)! */
#define XFPIDS_CLANINVITE 0x00a5
#define XFPIDS_CLANEVENTS 0x00aa
#define XFPIDS_CLANEVENTDELETED 0x00ab
#define XFPIDS_CLANNEWS 0x00b1
#define XFPIDS_GC_LIST 0x009b
#define XFPIDS_GC_CNAME 0x015e
#define XFPIDS_GC_JOININFO 0x015f
#define XFPIDS_GC_JOIN 0x0161
#define XFPIDS_GC_LEAVE 0x0162
#define XFPIDS_GC_MESSAGE 0x0163
#define XFPIDS_GC_INVITE 0x0164
#define XFPIDS_GC_CLVL 0x0165
#define XFPIDS_GC_REQINFO 0x0166
#define XFPIDS_GC_KICK 0x0167
#define XFPIDS_GC_VOICESTATUS 0x0168
#define XFPIDS_GC_VOICEHOSTINFO 0x016b
#define XFPIDS_GC_VOICELEAVE 0x016d
#define XFPIDS_GC_VOICEJOIN 0x016f
#define XFPIDS_GC_ROOMINFO 0x0170
#define XFPIDS_GC_CDEFLVL 0x0172
#define XFPIDS_GC_CMOTD 0x0176
#define XFPIDS_GC_CALLOWVOICE 0x0177
#define XFPIDS_GC_VOICESESSION 0x017f
#define XFPIDS_GC_QNAME 0x0180
#define XFPIDS_GC_CPASSWORD 0x0181
#define XFPIDS_GC_CACCESS 0x0182
#define XFPIDS_GC_INVITEDENY 0x0183
#define XFPIDS_GC_CSILENCE 0x0184
#define XFPIDS_GC_CJOINPARTMSG 0x0185
#define XFPIDS_FAVORITES 0x0094
#define XFPIDS_FRIENDFAV 0x0095
#define XFPIDS_SERVERS 0x0096
#define XFPIDS_MYVIDEOS 0x00b3
#define XFPIDS_LIVEVIDEO 0x00b8

/*** Source: dev/xfire/XfirePacketHelper.h ***/
#define SHORT_ATTRIBUTE(X) (unsigned const char *)#X
struct PairedList {
	LinkedList *names;
	LinkedList *values;
};

/*** Source: dev/xfire/library.h ***/
#define OPENFIREC_VER_MAJOR 0
#define OPENFIREC_VER_MINOR 2
#define OPENFIREC_VER_API 2
#define OPENFIREC_VER_BUILD 11
#define OPENFIREC_COMPATIBLE 0
#define OPENFIREC_MAYBE_COMPATIBLE 1
#define OPENFIREC_NOT_COMPATIBLE 2

/*** Source: dev/xfire/XfirePacket.h ***/
#define XfirePattrFree_internal(o) XfirePattrFree(o)
#define XFP_PACKET_MAXSIZE 0xffff
#define XFP_SIZE_PACKETLENGTH 2
#define XFP_MASK_PACKETLENGTH 0xffff
#define XFP_SIZE_PACKETID 2
#define XFP_MASK_PACKETID 0xffff
#define XFP_SIZE_ATTRIBUTECOUNT 1
#define XFP_MASK_ATTRIBUTECOUNT 0xff
#define XFP_SIZE_HEADER XFP_SIZE_PACKETLENGTH + XFP_SIZE_PACKETID + XFP_SIZE_ATTRIBUTECOUNT
#define XFP_SIZE_ATTRIBUTENAMELENGTH 1
#define XFP_MASK_ATTRIBUTENAMELENGTH 0xff
#define XFP_SIZE_SHORTATTRIBUTENAME 1
#define XFP_MASK_SHORTATTRIBUTENAME 0xff
#define XFP_SIZE_ATTRIBUTETYPE 1
#define XFP_MASK_ATTRIBUTETYPE 0xff
#define XFP_SIZE_ATTRINTVALUE 4
#define XFP_MASK_ATTRINTVALUE 0xffffffff
#define XFP_SIZE_ATTRBOOLEANVALUE 1
#define XFP_MASK_ATTRBOOLEANVALUE 0xff
#define XFP_SIZE_ATTRLONGVALUE 8
#define XFP_MASK_ATTRLONGVALUE 0xffffffffffffffffLL
#define XFP_SIZE_ATTRSTRINGLENGTH 2
#define XFP_MASK_ATTRSTRINGLENGTH 0xffff
#define XFP_SIZE_ATTRSIDVALUE 16
#define XFP_SIZE_ATTRGCIDVALUE 21
#define XFP_SIZE_ATTRLISTLENGTH 2
#define XFP_MASK_ATTRLISTLENGTH 0xffff
#define XFP_TYPE_STRING 0x01
#define XFP_TYPE_INT 0x02
#define XFP_TYPE_SID 0x03
#define XFP_TYPE_LIST 0x04
#define XFP_TYPE_PACKET 0x05
#define XFP_TYPE_GCID 0x06
#define XFP_TYPE_LONG 0x07
#define XFP_TYPE_BOOLEAN 0x08
#define XFP_TYPE_NPACKET 0x09
#ifdef DEBUG
        #define xfdbgprintf(level, x) if(inst->debug>=level) printf x
#else
        #define xfdbgprintf(level, x)
#endif
struct XfirePacket
{
        unsigned int    length;     /* Length of the network packet */
        unsigned int    pid;        /* Packet ID number */
        unsigned int    attrs;      /* Number of attributes */
                 int    shortnames; /* Are the attribute names short or long */
   struct XfirePattr ** attributes; /* Pointer to a table of attribute pointers */
};
struct XfirePattr
{
        unsigned int    aid;        /* Attribute type */
                void  * attr;       /* Attribute value */
          non0string  * name;       /* Attribute name */
};
struct XfirePattr4
{
        unsigned int    aid;        /* Attributes type */
        unsigned int    size;       /* Number of attributes in the list */
                void ** attr;       /* Attribute value */
};

/*** Source: dev/xfire/networking.h ***/
		#define INET_ADDRSTRLEN 16
		#define closesocket(x) close((x))

/*** Source: dev/xfire/XfirePacketDebug.h ***/

/*** Source: dev/xfire/library.c ***/
DLLIMPORT(int) openfirec_compatibility(int major, int minor, int api, int build) ;
DLLIMPORT(char *) get_openfirec_version(void) ;

/*** Source: dev/xfire/XfirePacket.c ***/
DLLIMPORT(void) XfirePacketFree(struct XfirePacket *obj) ;
DLLIMPORT(void) XfirePattr4Free(struct XfirePattr4 *obj) ;
DLLIMPORT(void) XfirePattrFree(struct XfirePattr *obj) ;
DLLIMPORT(struct XfirePacket*) XfirePacketParse(non0string *data) ;
DLLIMPORT(struct XfirePacket*) XfirePacketCreate(unsigned int attributes, int shortnames) ;
DLLIMPORT(unsigned int) XfirePacketGetPID(non0string *data) ;
DLLIMPORT(non0string*) XfireStreamFromPacket(struct XfirePacket *packet) ;

/*** Source: dev/xfire/XfirePacketHelper.c ***/
DLLIMPORT(struct XfirePattr*) XfireAttributeString(non0string *name, non0string* content) ;
DLLIMPORT(struct XfirePattr*) XfireAttributeInt(non0string *name, unsigned int content) ;
DLLIMPORT(struct XfirePattr*) XfireAttributeBool(non0string *name, unsigned int content) ;
DLLIMPORT(struct XfirePattr*) XfireAttributeLong(non0string *name, unsigned long long int content) ;
DLLIMPORT(struct XfirePattr*) XfireAttributeSid(non0string *name, non0string *content) ;
DLLIMPORT(struct XfirePattr*) XfireAttributeGcid(non0string *name, non0string *content) ;
DLLIMPORT(struct XfirePattr*) XfireAttributeList(non0string *name, struct XfirePattr4 *content) ;
DLLIMPORT(struct XfirePattr*) XfireAttributePacket(non0string *name, struct XfirePacket *content) ;
DLLIMPORT(int) XfirePacketSetAttribute(struct XfirePacket *packet, unsigned int index, struct XfirePattr *attribute) ;
DLLIMPORT(int) XfireRecv(int sock, non0string **data, unsigned char *recvbuffer, size_t *current_buffer_length) ;
DLLIMPORT(int) XfireSend(int sock, non0string *data, size_t completed) ;
DLLIMPORT(struct XfirePattr*) XfirePacketGetAttributeByName(struct XfirePacket *packet, non0string *name) ;
DLLIMPORT(struct PairedList*) XfireStringPairsSplit(non0string *pairs) ;
DLLIMPORT(LinkedList*) XfirePacketGetListAttribute(struct XfirePacket *packet, unsigned const char *name) ;
DLLIMPORT(non0string*) XfirePacketGetStringAttribute(struct XfirePacket *packet, unsigned const char *name) ;
DLLIMPORT(struct XfirePacket*) XfirePacketGetPacketAttribute(struct XfirePacket *packet, unsigned const char *name) ;
DLLIMPORT(unsigned int*) XfirePacketGetIntegerAttribute(struct XfirePacket *packet, unsigned const char *name) ;
DLLIMPORT(struct XfirePattr4*) XfirePacketCreateListAttribute(LinkedList *list, unsigned int aid) ;
DLLIMPORT(int) XfSendAll(int s, non0string *data) ;
DLLIMPORT(int) XfRecvAll(int s, non0string **data, unsigned char *buffer, size_t *buflength) ;
DLLIMPORT(struct XfirePacket*) XfirePHo_Init(unsigned int pid, unsigned int attrs, int shortnames) ;
DLLIMPORT(int) XfirePHo_AddAttribute(struct XfirePacket *p, const unsigned char *name,
		unsigned int aid, void *data) ;
DLLIMPORT(non0string*) XfirePHo_HashPassword(non0string *username,
		non0string *password) ;
DLLIMPORT(non0string*) XfirePHo_HashWithSalt(non0string *pwhash,
		non0string *salt) ;
DLLIMPORT(non0string*) XfirePHo_HashPasswordWithSalt(non0string *username,
		non0string *password, non0string *salt) ;

/*** Source: dev/xfire/XfirePacketDebug.c ***/
DLLIMPORT(void) DumpPacket(struct XfirePacket *testpack, const char * indent, const char *color1, const char *color2) ;

/*** Source: dev/xfire/XfirePacketAnalyze.c ***/
DLLIMPORT(XFINST) XfireInstance(int socketid) ;
DLLIMPORT(unsigned int) XfireDefaultPreferences(unsigned int initials) ;
DLLIMPORT(void) FreeXfireInstance(XFINST obj) ;
DLLIMPORT(struct XfFriend*) XfireFriend(void) ;
DLLIMPORT(void) FreeXfireFriend(struct XfFriend *obj) ;
DLLIMPORT(struct XfFavoriteServers*) XfireFavoriteServers(void) ;
DLLIMPORT(void) FreeXfireFavoriteServers(struct XfFavoriteServers *obj) ;
DLLIMPORT(struct XfGameData*) XfireGameData(
	unsigned int gameid, unsigned int gameip, unsigned int gameport
) ;
DLLIMPORT(void) FreeXfireGameData(struct XfGameData *obj) ;
DLLIMPORT(struct XfGameDataExt*) XfireGameDataExt(void) ;
DLLIMPORT(void) FreeXfireGameDataExt(struct XfGameDataExt *obj) ;
DLLIMPORT(struct XfFriendExt*) XfireFriendExtData(void) ;
DLLIMPORT(void) FreeXfireFriendExtData(struct XfFriendExt *obj) ;
DLLIMPORT(struct XfBroadcast*) XfireBroadcast(void) ;
DLLIMPORT(void) FreeXfireBroadcast(struct XfBroadcast *obj) ;
DLLIMPORT(struct XfFriendP2P*) XfireFriendP2Pinfo(void) ;
DLLIMPORT(void) FreeXfireFriendP2Pinfo(struct XfFriendP2P *obj) ;
DLLIMPORT(struct XfFriendsGroup*) XfireFriendsGroup(void) ;
DLLIMPORT(void) FreeXfireFriendsGroup(struct XfFriendsGroup *obj) ;
DLLIMPORT(void) FreeXfireFriendsGroupFull(struct XfFriendsGroup *obj) ;
DLLIMPORT(struct XfChatRoom*) XfireChatRoom(void) ;
DLLIMPORT(void) FreeXfireChatRoom(struct XfChatRoom *obj) ;
DLLIMPORT(struct XfChatRoomUser*) XfireChatRoomUser(struct XfFriend *user, unsigned int permission) ;
DLLIMPORT(void) FreeXfireChatRoomUser(struct XfChatRoomUser *obj) ;
DLLIMPORT(struct XfChatRoomVoice*) XfireChatRoomVoice(void) ;
DLLIMPORT(void) FreeXfireChatRoomVoice(struct XfChatRoomVoice *obj) ;
DLLIMPORT(struct XfVoiceHostUser*) XfireVoiceHostUser(void) ;
DLLIMPORT(void) FreeXfireVoiceHostUser(struct XfVoiceHostUser *obj) ;
DLLIMPORT(void) FreeXfireChatRoomUserFull(struct XfChatRoomUser *obj) ;
DLLIMPORT(struct XfClan*) XfireClan(unsigned int clanid) ;
DLLIMPORT(void) FreeXfireClan(struct XfClan *obj) ;
DLLIMPORT(struct XfClanMember*) XfireClanMember(struct XfFriend *user, non0string *nick, struct XfClan *xfc) ;
DLLIMPORT(void) FreeXfireClanMember(struct XfClanMember *obj) ;
DLLIMPORT(struct XfClanNews*) XfireClanNews(unsigned int newsid) ;
DLLIMPORT(void) FreeXfireClanNews(struct XfClanNews *obj) ;
DLLIMPORT(struct XfClanEvent*) XfireClanEvent(unsigned int eventid) ;
DLLIMPORT(void) FreeXfireClanEvent(struct XfClanEvent *obj) ;
DLLIMPORT(struct XfScreenshotInfo*) XfireScreenshotInfo(void) ;
DLLIMPORT(void) FreeXfireScreenshotInfo(struct XfScreenshotInfo *obj) ;
DLLIMPORT(struct XfVideoInfo*) XfireVideoInfo(void) ;
DLLIMPORT(void) FreeXfireVideoInfo(struct XfVideoInfo *obj) ;
DLLIMPORT(struct XfGameServerList*) XfireGameServerList(unsigned int gameid, LinkedList *servers) ;
DLLIMPORT(void) FreeXfireGameServerList(struct XfGameServerList *obj) ;
DLLIMPORT(int) XfireSeqConnect(XFINST inst, struct sockaddr_in *address) ;
DLLIMPORT(int) XfireInst_DefaultConnect(XFINST inst, char *hostname) ;
DLLIMPORT(struct XfNetworkHandler*) XfireInst_RegisterHandler(
	XFINST inst, unsigned int pid, void *func, void *freedata
) ;
DLLIMPORT(unsigned int) XfireInst_UnregisterHandler(
	XFINST inst, unsigned int pid, void *func, void *freedata
) ;
DLLIMPORT(unsigned int) XfireInst_SendPacket(XFINST inst,
	struct XfirePacket *packet
) ;
DLLIMPORT(int) XfireInst_SendMessage(XFINST inst,
	struct XfFriend *xff, non0string *msg
) ;
DLLIMPORT(int) XfireInst_SendMessageC(XFINST inst,
	struct XfFriend *xff, non0string *msg
) ;
DLLIMPORT(int) XfireInst_UserLogin(XFINST inst,
	non0string *username, non0string *password, non0string *salt,
	unsigned int flags
) ;
DLLIMPORT(int) XfireInst_UserLoginSaved(XFINST inst,
	non0string *username, non0string *pwhash, non0string *salt,
	unsigned int flags
) ;
DLLIMPORT(int) XfireInst_FD_SET_read(XFINST inst, int fd) ;
DLLIMPORT(int) XfireInst_FD_SET_write(XFINST inst, int fd) ;
DLLIMPORT(int) XfireInst_FD_CLR_read(XFINST inst, int fd) ;
DLLIMPORT(int) XfireInst_FD_CLR_write(XFINST inst, int fd) ;
DLLIMPORT(int) XfireInst_CheckNetwork(XFINST inst, struct timeval *timeout,
	fd_set *readset, fd_set *writeset) ;
DLLIMPORT(int) XfireInst_ProcessSend(XFINST inst) ;
DLLIMPORT(int) XfireInst_ProcessRecv(XFINST inst) ;
DLLIMPORT(int) XfireInst_ProcessRecvPacket(XFINST inst, non0string *data, struct XfirePacket *packet) ;
DLLIMPORT(struct XfClan*) XfireInst_AddNewClan(XFINST inst, unsigned int clanid) ;
DLLIMPORT(struct XfClan*) XfireInst_FindClanByClanid(XFINST inst, unsigned int clanid) ;
DLLIMPORT(struct XfFriendsGroup*) XfireInst_FindGroupByGroupid(XFINST inst, unsigned int groupid) ;
DLLIMPORT(struct XfFriend*) XfireInst_FindUserByUserid(XFINST inst, unsigned int userid) ;
DLLIMPORT(struct XfFriend*) XfireInst_FindUserByUsername(XFINST inst, non0string *username) ;
DLLIMPORT(struct XfFriend*) XfireInst_FindUserBySid(XFINST inst, non0string *sid) ;
DLLIMPORT(struct XfChatRoom*) XfireInst_FindCreateChatRoom(XFINST inst, non0string *gcid) ;
DLLIMPORT(struct XfChatRoom*) XfireInst_FindChatRoom(XFINST inst, non0string *gcid) ;
DLLIMPORT(struct XfChatRoom*) XfireInst_FindChatRoomByName(XFINST inst, non0string *name) ;
DLLIMPORT(struct XfChatRoomUser*) XfireInst_FindChatRoomUserByXfFriend(
		XFINST inst, struct XfChatRoom *xfgc, struct XfFriend *xff) ;
DLLIMPORT(struct XfClanEvent*) XfireInst_FindClanEventByEventid(
		XFINST inst, struct XfClan *xfc, unsigned int eventid) ;
DLLIMPORT(char*) XfireUtil_AvatarURL(struct XfFriend *user) ;
DLLIMPORT(unsigned char*) XfireUtil_GetNickname(struct XfFriend *user) ;
DLLIMPORT(int) XfireUtil_IsUserOnline(struct XfFriend *user) ;
DLLIMPORT(unsigned char *) XfireUtil_IPchar(unsigned int ip, unsigned char *ipchar) ;
DLLIMPORT(unsigned int) XfireUtil_IPvalue(unsigned char *ipchar) ;

/*** Source: dev/xfire/packet_creation/XfirePacketsClientFriendsList.c ***/
DLLIMPORT(struct XfirePacket) * XfirePHc_AddFriend(non0string *username, non0string *text) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_AcceptFriend(non0string *username) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_RejectFriend(non0string *username) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_DeleteFriend(unsigned int userid) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_SearchFriends(non0string *term) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_ChangeNick(non0string *nickname) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GameStatus(unsigned int gameid,
		unsigned int gameip, unsigned int gameport) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_FriendGroupRename(unsigned int groupid,
		non0string *name) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_CustomStatus(non0string *text) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_RequestFriendData(unsigned int userid) ;

/*** Source: dev/xfire/packet_creation/XfirePacketsClientSystem.c ***/
DLLIMPORT(struct XfirePacket) * XfirePHc_Heartbeat(void) ;

/*** Source: dev/xfire/packet_creation/XfirePacketsClientChatRoom.c ***/
DLLIMPORT(struct XfirePacket) * XfirePHc_GCJoin(non0string *gcid,
		non0string *gcname, unsigned int rqindex, unsigned int rtype,
		non0string *pass, unsigned int autoname
	) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GCPart(non0string *gcid) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GCMsg(non0string *gcid,
		non0string *text) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GCRequestBasicInfo(struct XfirePattr4 *gcids) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GCRequestDetailedInfo(non0string *gcid) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GCInvite(non0string *gcid,
		struct XfirePattr4 *userids) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GCAdminRename(non0string *gcid,
		non0string *gcname) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GCAdminMOTD(non0string *gcid,
		non0string *gcmotd) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GCAdminUserPerm(non0string *gcid,
		unsigned int userid, unsigned int gcperm) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GCSave(non0string *gcid, unsigned int gcset) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GCAdminAllowVoice(non0string *gcid,
		unsigned int gcset) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GCAdminForceVoiceOff(non0string *gcid) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GCAdminSetDefaultPerm(non0string *gcid,
		unsigned int gcperm) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_GCAdminKick(non0string *gcid, unsigned int userid) ;

/*** Source: dev/xfire/packet_creation/XfirePacketsClientLogin.c ***/
DLLIMPORT(struct XfirePacket) * XfirePHc_ClientVersion(unsigned int version) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_UserLogin(non0string *username, non0string *password,
		non0string *salt, unsigned int flags) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_UserLoginSaved(non0string *username, non0string *pwhash,
		non0string *salt, unsigned int flags) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_ClientInfo(non0string *lang, non0string *skin, 
		non0string *theme, non0string *partner) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_PeerInfo(unsigned int conn, unsigned int nat,
		unsigned int sec, unsigned int clientip, unsigned int naterr,
		non0string *upnpinfo) ;

/*** Source: dev/xfire/packet_creation/XfirePacketsClientIM.c ***/
DLLIMPORT(struct XfirePacket) * XfirePHc_InstantMessage(non0string *sid, unsigned int imindex, non0string *message) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_IMack(non0string *sid, unsigned int imindex) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_TypingNotification(non0string *sid, unsigned int imindex, unsigned int typing) ;
DLLIMPORT(struct XfirePacket) * XfirePHc_P2PExchange(non0string *sid, unsigned int ip,
		unsigned int port, unsigned int localip, unsigned int localport,
		unsigned int nattype, non0string *salt) ;

/*** Source: dev/xfire/packet_creation/XfirePacketsServerSystem.c ***/
DLLIMPORT(struct XfirePacket) * XfirePHs_Heartbeat(void) ;
#endif
